<?php include("includes/session.php"); ?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title><?php echo $lang['PAGE_TITLE_ADMIN_LINKS']; ?></title>
<?php include("header.php"); ?>
<br />
<center>
<?php 
if($session->userlevel <= USER_LEVEL)
{
	echo "<center><h2>Restricted Area</h2></center>";
}
else
{
?>
<?php
if(isset($_SESSION['linksuccess']))
{
	if($_SESSION['linksuccess'])
	{
		echo "<center><h3>Link Successfully Added</h3></center>";
		echo "<center><a href=\"adminLinks.php\">Add Link</a></center>";
	}
	else
	{
		echo "<center><h3>Link Failed to be Added</h3></center>";
		echo "<center>Please Try Again Later.</center>";
	}
	unset($_SESSION['linksuccess']);
}
else if(isset($_SESSION['linkeditsuccess']))
{
	if($_SESSION['linkeditsuccess'])
	{
		echo "<center><h3>Link Successfully Edited</h3></center>";
		echo "<center><a href=\"adminLinks.php\">Add Link</a></center>";
	}
	else
	{
		echo "<center><h3>Link Failed to be Edited</h3></center>";
		echo "<center>Please Try Again Later.</center>";
	}
	unset($_SESSION['linkeditsuccess']);
}
else if(isset($_GET['edit']))
{
	$result = $database->query("SELECT * FROM ".TBL_LINKS." WHERE id='".$_GET['edit']."'");
	$link = mysql_fetch_array($result);
?>
<table cellpadding="10" cellspacing="0" class="border">
<tr><td class="title" align="left"><?php echo $lang['ADMIN_EDIT_LINKS']; ?></td></tr>
<tr>
	<td>
	<form action="includes/process.php" method="POST">
	<table cellspacing="0" cellpadding="3">
	<tr>
		<td><b>Creator:</b> <?php echo $form->error("creator"); ?></td>
	</tr>
	<tr>
		<td><input type="text" name="creator" size="50" value="<?php if($form->value("creator")==""){ echo $link['creator']; }else{ echo $form->value("creator"); } ?>"/></td>
	</tr>
	<tr>
		<td><b>Link:</b> <?php echo $form->error("link"); ?></td>
	</tr>
	<tr>
		<td><input type="text" name="link" size="50" value="<?php if($form->value("link")==""){ echo $link['link']; }else{ echo $form->value("link"); } ?>"/></td>
	</tr>
	<tr>
		<td><b>URL:</b> <?php echo $form->error("url"); ?></td>
	</tr>
	<tr>
		<td><input type="text" name="url" size="50" value="<?php if($form->value("url")==""){ echo $link['url']; }else{ echo $form->value("url"); } ?>"/></td>
	</tr>
	<tr>
		<td><b>Description:</b> <?php echo $form->error("description"); ?></td>
	</tr>
	<tr>
		<td><textarea name="description" cols="38" rows="4"><?php if($form->value("description")==""){ echo $link['description']; }else{ echo $form->value("description"); } ?></textarea></td>
	</tr>
	<tr>
		<td align="right">
		<input type="hidden" name="subEditLink" value="<?php echo $link['id']; ?>" />
		<input type="submit" value="Edit Link" />
		</td>
	</tr>
	</table>
	</form>
	</td>
</tr>
</table>
<?php
}
else
{
?>
<table cellpadding="10" cellspacing="0" class="border">
<tr><td class="title" align="left"><?php echo $lang['ADMIN_ADD_LINKS']; ?></td></tr>
<tr>
	<td>
	<form action="includes/process.php" method="POST">
	<table cellspacing="0" cellpadding="3">
	<tr>
		<td><b><?php echo $lang['ADMIN_ADD_LINKS_CREATOR']; ?></b> <?php echo $form->error("creator"); ?></td>
	</tr>
	<tr>
		<td><input type="text" name="creator" size="50" value="<?php echo $form->value("creator"); ?>"/></td>
	</tr>
	<tr>
		<td><b><?php echo $lang['ADMIN_ADD_LINKS_LINK']; ?></b> <?php echo $form->error("link"); ?></td>
	</tr>
	<tr>
		<td><input type="text" name="link" size="50" value="<?php echo $form->value("link"); ?>"/></td>
	</tr>
	<tr>
		<td><b><?php echo $lang['ADMIN_ADD_LINKS_URL']; ?></b> <?php echo $form->error("url"); ?></td>
	</tr>
	<tr>
		<td><input type="text" name="url" size="50" value="<?php echo $form->value("url"); ?>"/></td>
	</tr>
	<tr>
		<td><b><?php echo $lang['ADMIN_ADD_LINKS_DESC']; ?></b> <?php echo $form->error("description"); ?></td>
	</tr>
	<tr>
		<td><textarea name="description" cols="38" rows="4"><?php echo $form->value("description"); ?></textarea></td>
	</tr>
	<tr>
		<td align="right">
		<input type="hidden" name="subAddLink" value="1" />
		<input type="submit" value="Add Link" />
		</td>
	</tr>
	</table>
	</form>
	</td>
</tr>
</table>
<?php
}
?>
<br /><br />
<table cellpadding="0" cellspacing="0">
<tr>
	<td class="topLeft"></td><td bgcolor="#dadada"></td><td class="topRight"></td>
</tr>
<tr bgcolor="#dadada">
<td></td><td>
<?php displayAdminLinks(); ?>
</td><td></td>
</tr>
<tr>
	<td class="bottomLeft"></td><td bgcolor="#dadada"></td><td class="bottomRight"></td>
</tr>
</table>
<?php
}
?>
</center>
<?php include("footer.php"); ?>